package admin

import (
	"game-server/app/common/request"
	"game-server/app/common/response"
	"game-server/app/services"
	"game-server/global"

	"github.com/gin-gonic/gin"
)

// GameAdd 新增游戏
// @Summary 新增游戏
// @Description 新增游戏
// @Tags 游戏管理
// @Accept json
// @Produce json
// @Param data body request.GameAddRequest true "请求参数"
// @Router /gameServer/admin/game/add [post]
func GameAdd(c *gin.Context) {
	var form request.GameAddRequest
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}

	global.App.Log.Info("新增游戏----")
	if err := services.GameService.CreateGame(form); err != nil {
		global.App.Log.Error(err.Error())
		response.BusinessFail(c, err.Error())
		return
	}

	response.Success(c, nil)
}

// GameList 游戏列表 分页条件查询
// @Summary 游戏列表 分页条件查询
// @Description 游戏列表 分页条件查询
// @Tags 游戏管理
// @Accept application/json
// @Produce application/json
// @Param data body request.GameListRequest true "请求参数"
// @Router /gameServer/admin/game/list [post]
func GameList(c *gin.Context) {
	var form request.GameListRequest
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}
	data, err := services.GameService.GetGameList(form)
	if err != nil {
		response.BusinessFail(c, err.Error())
		return
	}
	response.Success(c, data)
}

// GameDel 删除游戏
// @Summary 删除游戏
// @Description 删除游戏
// @Tags 游戏管理
// @Accept application/json
// @Produce application/json
// @Param data body request.GameDelRequest true "请求参数"
// @Router /gameServer/admin/game/del [post]
func GameDel(c *gin.Context) {
	var form request.GameDelRequest
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}
	global.App.Log.Info("删除游戏----")
	if err := services.GameService.DelGame(form); err != nil {
		global.App.Log.Error(err.Error())
		response.BusinessFail(c, err.Error())
		return
	}
	response.Success(c, nil)
}

// GameUpdate 更新游戏
// @Summary 更新游戏
// @Description 更新游戏
// @Tags 游戏管理
// @Accept application/json
// @Produce application/json
// @Param data body request.GameUpdateRequest true "请求参数"
// @Router /gameServer/admin/game/update [post]
func GameUpdate(c *gin.Context) {
	var form request.GameUpdateRequest
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}
	global.App.Log.Info("更新游戏----")
	if err := services.GameService.UpdateGame(form); err != nil {
		global.App.Log.Error(err.Error())
		response.BusinessFail(c, err.Error())
		return
	}
	response.Success(c, nil)
}

// GameBatchDel 批量删除游戏
// @Summary 批量删除游戏
// @Description 批量删除游戏
// @Tags 游戏管理
// @Accept application/json
// @Produce application/json
// @Param data body request.GameBatchDelRequest true "请求参数"
// @Router /gameServer/admin/game/batchDel [post]
func GameBatchDel(c *gin.Context) {
	var form request.GameBatchDelRequest
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}
	global.App.Log.Info("批量删除游戏----")
	if err := services.GameService.BatchDelGame(form); err != nil {
		global.App.Log.Error(err.Error())
		response.BusinessFail(c, err.Error())
		return
	}
	response.Success(c, nil)
}
